home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / conflict.0 / conflict / conflict-6.0 / unix.c < prev   
Encoding:
C/C++ Source or Header  |  1995-03-15  |  2.0 KB  |  98 lines

  1. /******************************************************************************
  2.  * Copyright 1995 by Thomas E. Dickey.  All Rights Reserved.                  *
  3.  *                                                                            *
  4.  * You may freely copy or redistribute this software, so long as there is no  *
  5.  * profit made from its use, sale trade or reproduction. You may not change   *
  6.  * this copyright notice, and it must be included in any copy made.           *
  7.  ******************************************************************************/
  8. #ifndef NO_IDENT
  9. static char *Id = "$Id: unix.c,v 6.0 1995/03/15 00:12:22 dickey Rel $";
  10. #endif
  11.  
  12. #include "conflict.h"
  13.  
  14. void    blip(c)
  15.     int    c;
  16. {
  17.     static    char    text[] = "?";
  18.     text[0] = (char)c;
  19.     write(fileno(stderr), text, 1);
  20. }
  21.  
  22. char *    fleaf(name)
  23.     char    *name;
  24. {
  25.     char    *leaf = strrchr(name, PATHNAME_SEP);
  26.     if (leaf != 0)
  27.         leaf++;
  28.     else
  29.         leaf = name;
  30.     return leaf;
  31. }
  32.  
  33. char *
  34. ftype (name)
  35.     char    *name;
  36. {
  37.     char    *leaf = fleaf(name);
  38.     char    *type = strrchr(leaf, '.');
  39.     if (type == 0)
  40.         type = leaf + strlen(leaf);
  41.     return type;
  42. }
  43.  
  44. #if !USE_INODE && !HAVE_REALPATH
  45. char    *my_realpath(given, actual)
  46.     char    *given;
  47.     char    *actual;
  48. {
  49.     char    current[MAXPATHLEN];
  50.     char    *extra = 0;
  51.     char    *result = 0;
  52.  
  53.     if (getwd(current) != 0) {
  54.         struct    stat    sb;
  55.  
  56.         if (stat(strcpy(actual, given), &sb) >= 0) {
  57.             if ((sb.st_mode & S_IFMT) != S_IFDIR) {
  58.                 extra = fleaf(given);
  59.                 if (extra == given) {
  60.                     (void) strcpy(actual, current);
  61.                 } else {
  62.                     actual[(int)(extra-given)] = EOS;
  63.                 }     
  64.             }
  65.             if (!strcmp(actual, current)) {
  66.                 result = actual;
  67.             } else if (chdir(actual) >= 0) {
  68.                 if (getwd(actual) != 0) {
  69.                     result = actual;
  70.                 }
  71.                 (void)chdir(current);
  72.             }
  73.             if (result != 0 && extra != 0) {
  74.                 char *s = actual + strlen(actual);
  75.                 *s++ = PATHNAME_SEP;
  76.                 (void)strcpy(s, extra);
  77.             }
  78.         }
  79.     }
  80.     return result;
  81. }
  82. #endif
  83.  
  84. #if !HAVE_STRDUP
  85. char    *my_strdup(s)
  86.     char    *s;
  87. {
  88.     if (s != 0) {
  89.         char    *t = malloc(strlen(s)+1);
  90.         if (t != 0) {
  91.             (void)strcpy(t, s);
  92.         }
  93.         s = t;
  94.     }
  95.     return s;
  96. }
  97. #endif
  98.